﻿using System;
using System.Windows.Forms;

namespace TextEditor
{
    

    public class A_NewFile : A_Action
    {
        public override string ActionName()
        {
            return "newfile";
        }

        public override bool Execute()
        {
            if (base.myOwnerDocument.Modified)
            {
                switch (MessageBox.Show("当前文档内容已修改,是否保存?", "系统提示", MessageBoxButtons.YesNoCancel))
                {
                    case DialogResult.Yes:
                        if (base.myOwnerDocument.GetActionByName("savedbfile").Execute())
                        {
                            break;
                        }
                        return false;

                    case DialogResult.Cancel:
                        return false;
                }
            }
            base.myOwnerDocument.BeginUpdate();
            base.myOwnerDocument.ClearContent();
            base.myOwnerDocument.EndUpdate();
            base.myOwnerDocument.Modified = false;
            base.myOwnerDocument.Refresh();
            return true;
        }

        public override bool isEnable()
        {
            return base.myOwnerDocument.CanModify();
        }
    }
}

